--[[
/**
 * 当前敌方血量百分比最低的英雄，每损失[0]%的血量，则攻击力增加[1]%
 * [1100,500]
 */
]]
---@class BuffEffect25100 : BaseBuffEffect
BuffEffect25100 = ClientFight.CreateClass("BuffEffect25100", ClientFight.BaseBuffEffect)
local t = BuffEffect25100
---@param fight Fight
---@param buff FighterBuff
function t:action(fight, buff, ...)
    local fighter = buff.target;
    local effectValues = buff.buffBean.f_BuffEffectValue;
    local armyTeam = fight.team[1 - fighter.teamIndex];
    local minFighter = nil; -- 血量百分比最低的英雄
    for target in pairs(armyTeam.fighters) do
        if (target:isSummons()) then
            goto continue;
        end
        if target:isDie() then
            goto continue;
            if (minFighter == nil) then
                minFighter = target;
                goto continue;
            end
            local targetHpPercent = target.hp * Global.TEN_THOUSANDTH
                    / FighterAttributeManager.getFightAttr(target, FighterAttributeEnum.HP);
            local minFighterHpPercent = minFighter.hp * Global.TEN_THOUSANDTH
                    / FighterAttributeManager.getFightAttr(minFighter, FighterAttributeEnum.HP);
            if (targetHpPercent < minFighterHpPercent) then
                minFighter = target;
            end
        end
        ::continue::
    end
    if (minFighter == nil) then
        return IBuffEffect.FAIL;
    else
        local maxHp = FighterAttributeManager.getFightAttr(minFighter, FighterAttributeEnum.HP);
        local loseHp = maxHp - minFighter.hp;
        local loseHpPercent = loseHp * Global.TEN_THOUSANDTH / maxHp;
        local addAtk = loseHpPercent / effectValues[1] * effectValues[2];
        buff.attributes.attributes[FighterAttributeEnum.ATK.id] =  addAtk;
        local logMinFighter = minFighter;
        SkillRoleMgr.savePathFile(
                "[" .. fight.frame .. "][EFFECT]Fighter " .. buff.target.fighterId .. " Buff"
                        .. buff.modelId .. " 当前敌方血量百分比最低的英雄，每损失[0]%的血量，则攻击力增加[1]% 血量最低的英雄:" .. logMinFighter.fighterId ..
                        "  增加攻击力:" .. addAtk
        );
    end

    ClientFight.BaseBuffEffect.action(self, fight, buff, ...);
    return IBuffEffect.SUCCESS_ATTRI_HAS_CHANGE;
end

t.New()